package baidu.ui.controls
{
    import baidu.ui.core.*;
    import flash.text.*;

    public class Label extends BUI
    {
        protected var _textField:TextField;
        protected var _text:String;
        protected var _ellipsis:Boolean;
        protected var _ellipsisIndex:int = -1;
        protected var _tail:String = "...";

        public function Label()
        {
            return;
        }

        public function get textField() : TextField
        {
            return this._textField;
        }

        public function get text() : String
        {
            return this._text;
        }

        public function set text(param1:String) : void
        {
            this._text = param1;
            invalidate(Invalidation.SIZE);
            return;
        }

        public function get displayText() : String
        {
            return this._textField.text;
        }

        public function get ellipsis() : Boolean
        {
            return this._ellipsis;
        }

        public function set ellipsis(param1:Boolean) : void
        {
            this._ellipsis = param1;
            invalidate(Invalidation.SIZE);
            return;
        }

        public function get ellipsisIndex() : int
        {
            return this._ellipsisIndex;
        }

        public function set ellipsisIndex(param1:int) : void
        {
            this._ellipsisIndex = param1;
            invalidate(Invalidation.SIZE);
            return;
        }

        public function get tail() : String
        {
            return this._tail;
        }

        public function set tail(param1:String) : void
        {
            this._tail = param1;
            invalidate(Invalidation.SIZE);
            return;
        }

        override protected function initUI() : void
        {
            super.initUI();
            setSize(100, 100);
            this._textField = new TextField();
            addChild(this._textField);
            return;
        }

        override protected function draw() : void
        {
            if (isInvalid(Invalidation.SIZE))
            {
                this.drawLayout();
                this.drawTextField();
            }
            super.draw();
            return;
        }

        protected function drawLayout() : void
        {
            this._textField.width = _width;
            this._textField.height = _height;
            return;
        }

        protected function drawTextField() : void
        {
            var _loc_1:String = null;
            var _loc_2:String = null;
            var _loc_3:String = null;
            this._textField.text = this._text;
            if (this._ellipsis)
            {
                if (this._textField.textWidth > this._textField.width)
                {
                    _loc_1 = this._text;
                    if (this._ellipsisIndex > (_loc_1.length - 1) || this._ellipsisIndex < -_loc_1.length)
                    {
                        trace("Error������ " + this._ellipsisIndex + " ���Ϸ����������?Χ��");
                        return;
                    }
                    if (this._ellipsisIndex < 0)
                    {
                        this._textField.text = this._tail + _loc_1.slice(_loc_1.length + this._ellipsisIndex + 1, _loc_1.length);
                        if (this._textField.textWidth > this._textField.width - 4)
                        {
                            trace("Error������ " + this._ellipsisIndex + " ���Ϸ����������ַ��ࡣ");
                            return;
                        }
                    }
                    else
                    {
                        this._textField.text = _loc_1.slice(0, this._ellipsisIndex) + this._tail;
                        if (this._textField.textWidth > this._textField.width - 4)
                        {
                            trace("Error������ " + this._ellipsisIndex + " ���Ϸ����������ַ��ࡣ");
                            return;
                        }
                    }
                    this._textField.text = this._text + this._tail;
                    while (this._textField.textWidth > this._textField.width - 4)
                    {
                        
                        if (this._ellipsisIndex < 0)
                        {
                            _loc_2 = _loc_1.slice(0, _loc_1.length + this._ellipsisIndex);
                            _loc_3 = _loc_1.slice(_loc_1.length + this._ellipsisIndex + 1, _loc_1.length);
                        }
                        else
                        {
                            _loc_2 = _loc_1.slice(0, this._ellipsisIndex);
                            _loc_3 = _loc_1.slice((this._ellipsisIndex + 1), _loc_1.length);
                        }
                        _loc_1 = _loc_2 + _loc_3;
                        this._textField.text = _loc_2 + this._tail + _loc_3;
                        if (_loc_1.length == 0)
                        {
                            break;
                        }
                    }
                }
            }
            return;
        }

    }
}
